package com.jinzhi.jzapi.utils;

import com.jinzhi.jzweb.domain.MemberApplyDO;
import com.jinzhi.jzweb.utils.ValuesUtil;
import org.apache.commons.lang3.StringUtils;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;

import static com.jinzhi.jzapi.utils.SpellHelper.getUpEname;



public class CerSynthesisUtil {

//    public static void main(String[] args) throws IOException {
//        String stuName = "张祥龙";
//        String stuImg = "D:/2.png";
//        String idCard = "411424198506241642";
//        String cerNumber = "JZ20412008010091";
//        String electronicSeal = "D:/upload/jzgz.png";
//
////        String backgroundPath = "D:/upload/证书模板参考（正面）.jpg";
////        String issueDate = "2020年6月15日";
////        String examinYear = "2020";
////        String examinMath = "12";
////        String cerLevelC = "中级";
////        String orgPrincipalImg = "";
////        String assPointPrincipalImg = "";
//        // 背景图路径，考生姓名，考生头像图路径，身份证号码，证书编号，发证时间，考试年份，考试月份，证书等级中文，发证机构公章图路径，机构负责人签章图路径，考核点签章图路径
//        // [backgroundPath, stuName, stuImg, idCard, cerNumber, issueDate, examinYear, examinMath, cerLevelC, electronicSeal, orgPrincipalImg, assPointPrincipalImg]
////        overlapImage(backgroundPath, stuName, stuImg, idCard, cerNumber, issueDate, examinYear, examinMath, cerLevelC,
////                electronicSeal, orgPrincipalImg, assPointPrincipalImg);
//
//        String backgroundPath1 = "D:/upload/kpCh.jpg";
//
//        String numPeriods = "01";
//        String trainingNumber = "6";
//        String traYear = "2020";
//        String traMath = "08";
//        String traDay = "18";
//        String cerYear = "2020";
//        String cerMath = "09";
//        String cerDay = "23";
//        String workUnit="湖南金职伟业现代家庭产业有限公司";
//        String effectiveDate = "2020-08-14至2023-08-14";
//        // 合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时）， 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章
//        // [type,backgroundPath,stuName,stuImg,idCard,cerNumber,numPeriods,trainingNumber,traYear,traMath,traDay,cerYear,cerMath,cerDay,electronicSeal]
//        //考评员-幼儿照护
//         //overTraExaImage(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit,1,electronicSeal);
//        //考评员-产后恢复
//        //overTraExaImageRecovery(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit,1,electronicSeal);
//        //师资
//        //prizeImage(backgroundPath1, stuName, cerNumber);
//        //督导员-结业证书
//        //overTraSupervisorGradiningImage(0,backgroundPath1, stuName, stuImg, idCard, cerNumber,numPeriods,trainingNumber,traYear,traMath,traDay,cerYear,cerMath,cerDay,electronicSeal,workUnit);
//        //考务技术员-结业证书
//        //overTraAraGradiningImage(0,backgroundPath1, stuName, stuImg, idCard, cerNumber,numPeriods,trainingNumber,traYear,traMath,traDay,cerYear,cerMath,cerDay,electronicSeal,workUnit);
//        //考务技术员证
//        //overTraExaAffImage(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit,electronicSeal);
//        //督导员证
//        overTraSupervisorExaAffImage(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit,electronicSeal);
//        //String backgroundPath2 = "D:/upload/考评员证-正面.jpg";
//        //String effectiveDate = "2020-08-14至2023-08-14";
//        // 背景图，学员姓名，学员图像， 身份证号码，证书编码，证书名称，有效日期
//        // [backgroundPath, stuName, stuImg, idCard, cerNumber, cerName, effectiveDate]
////        overTraExaImage(backgroundPath2, stuName, stuImg, idCard, cerNumber, effectiveDate);
//    }






//    public static void main(String[] args) throws IOException {
//        String stuName = "孟智超";
//        String stuImg = "D:/2.png";
//        String idCard = "411424198506241642";
//        String cerNumber = "JZ20412008010093";
//        String electronicSeal = "D:/upload/jzgz.png";
//
////        String backgroundPath = "D:/upload/证书模板参考（正面）.jpg";
////        String issueDate = "2020年6月15日";
////        String examinYear = "2020";
////        String examinMath = "12";
////        String cerLevelC = "中级";
////        String orgPrincipalImg = "";
////        String assPointPrincipalImg = "";
//        // 背景图路径，考生姓名，考生头像图路径，身份证号码，证书编号，发证时间，考试年份，考试月份，证书等级中文，发证机构公章图路径，机构负责人签章图路径，考核点签章图路径
//        // [backgroundPath, stuName, stuImg, idCard, cerNumber, issueDate, examinYear, examinMath, cerLevelC, electronicSeal, orgPrincipalImg, assPointPrincipalImg]
////        overlapImage(backgroundPath, stuName, stuImg, idCard, cerNumber, issueDate, examinYear, examinMath, cerLevelC,
////                electronicSeal, orgPrincipalImg, assPointPrincipalImg);
//
////        String backgroundPath1 = "D:/upload/yxxy.jpg";
////        String backgroundPath1 = "D:/upload/yxzzdw.jpg";
//
//        String backgroundPath1 = "D:/upload/jyzs.jpg";
//
//        String numPeriods = "01";
//        String trainingNumber = "6";
//        String traYear = "2020";
//        String traMath = "08";
//        String traDay = "18";
//        String cerYear = "2020";
//        String cerMath = "09";
//        String cerDay = "23";
//        String workUnit="湖南金职伟业现代家庭产业有限公司";
//        String effectiveDate = "2020-08-14至2023-08-14";
//        // 合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时）， 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章
//        // [type,backgroundPath,stuName,stuImg,idCard,cerNumber,numPeriods,trainingNumber,traYear,traMath,traDay,cerYear,cerMath,cerDay,electronicSeal]
//        //考评员
//        // overTraExaImage(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit,1);
//        //师资
//
//        //优秀学员
////        prizeImageYXXY(0,backgroundPath1, stuName, cerNumber,electronicSeal,"2022","05","16","一");
//
//
////        //优秀组织单位
////        prizeImageYXZZDW(0,backgroundPath1,"百度科技有限公司",cerNumber,electronicSeal,"2022","05","16","一");
//
//
//        //结业证书
//        prizeImageJYZS(0,backgroundPath1,stuName,cerNumber,electronicSeal,traYear,"05","17","1","410311199907554621","百度科技有限公司","48","2021","06");
//
//
//
//
//
//        //督导员-结业证书
//        //overTraSupervisorGradiningImage(0,backgroundPath1, stuName, stuImg, idCard, cerNumber,numPeriods,trainingNumber,traYear,traMath,traDay,cerYear,cerMath,cerDay,electronicSeal,workUnit);
//        //考务技术员-结业证书
//        //overTraAraGradiningImage(0,backgroundPath1, stuName, stuImg, idCard, cerNumber,numPeriods,trainingNumber,traYear,traMath,traDay,cerYear,cerMath,cerDay,electronicSeal,workUnit);
//        //考务技术员证
//        //overTraExaAffImage(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit);
//        //督导员证
//        //overTraSupervisorExaAffImage(backgroundPath1, stuName, stuImg, idCard, cerNumber, effectiveDate,workUnit);
//        //String backgroundPath2 = "D:/upload/考评员证-正面.jpg";
//        //String effectiveDate = "2020-08-14至2023-08-14";
//        // 背景图，学员姓名，学员图像， 身份证号码，证书编码，证书名称，有效日期
//        // [backgroundPath, stuName, stuImg, idCard, cerNumber, cerName, effectiveDate]
////        overTraExaImage(backgroundPath2, stuName, stuImg, idCard, cerNumber, effectiveDate);
//    }
//





//
//
//    public static void main(String[] args) throws IOException {
//        String stuName = "孟智超"; //姓名
//        String stuImg = "D:/upload/mzc.jpg"; //一寸照片
//        String idCard = "411424198506241642"; //身份证号
//        String cerNumber = "JZ20412008010093"; //证书编号
//        String electronicSeal = "D:/upload/jzgz.png"; //公章
//        String backgroundPath1 = "D:/upload/chhf_sz_zj.jpg"; //证书模板位置
//        String numPeriods = "6"; //学时
//        String trainingNumber = "01"; //期数
//        String traYear = "2020"; //培训日期
//        String traMath = "08"; //培训日期
//        String traDay = "18"; //培训日期
//        String cerYear = "2020"; //培训截止日期
//        String cerMath = "09"; //培训截止日期
//        String cerDay = "23"; //培训截止日期
//        String workUnit="湖南金职伟业现代家庭产业有限公司"; //工作单位
//
//
//
//        prizeImageSHiZi4(0,backgroundPath1,stuName,stuImg,cerNumber,electronicSeal,traYear,traMath,traDay,trainingNumber,idCard,workUnit,numPeriods,cerYear,cerMath,cerDay);
//    }






//        public static void main(String[] args) throws IOException {
//        String stuName = "孟智超"; //姓名
//        String idCard = "411424198506241642"; //身份证号
//        String cerNumber = "JZ20412008010093"; //证书编号
//        String electronicSeal = "D:/upload/jzwy_jt_dzgz.png"; //公章
//        String backgroundPath1 = "D:/upload/zyzfwzs.jpg"; //证书模板位置
//        String numPeriods = "6"; //学时
//        String traYear = "2020"; //培训日期
//        String traMath = "08"; //培训日期
//        String traDay = "20"; //培训日期
//        String cerYear = "2023"; //培训截止日期
//        String cerMath = "12"; //培训截止日期
//        String cerDay = "26"; //培训截止日期
//        String workUnit="湖南金职伟业现代家庭产业有限公司"; //工作单位oundPath
//            prizeImagZYZFWZS(0,backgroundPath1,stuName,electronicSeal,numPeriods,cerYear,cerMath,cerDay,cerNumber);
//    }





    /**
     * 考务技术员证合成方法-幼儿照护-产后恢复
     *
     * @Description:  考评员培训照片合成方法 ,参数说明：背景图，学员姓名，学员图像， 身份证号码，证书编码，证书名称，有效日期，工作单位
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, cerName, effectiveDate]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-20
     */
    public static String overTraExaAffImage(String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String effectiveDate,String workUnit,String electronicSeal) throws IOException {
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
        BufferedImage backgroundImage = resizeImage(705, 983, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(195, 268, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(255, 255, 255);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 33));
        //考生姓名
        g.drawString(stuName, 274, 740);

        g.setFont(new Font("黑体", 2, 40));
        //考生头像
        g.drawImage(stuImgs, 255, 422, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 25));
        //身份证
        g.drawString(idCard, 254, 797);
        //证书编号
        g.drawString(cerNumber, 254, 837);

        //有效日期
        g.drawString(effectiveDate, 254, 875);
        if(workUnit.length()>16) {
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 20));
            //工作单位
            g.drawString(workUnit.substring(0,16), 254, 910);
            g.drawString(workUnit.substring(16,workUnit.length()), 254, 930);
        }else{
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 21));
            //工作单位
            g.drawString(workUnit, 254, 913);
        }
        //电子公章，以水印的形式插入
        //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
        ImageIcon imgIcon = new ImageIcon(electronicSeal);
        //得到Image对象。
        Image img = imgIcon.getImage();
        float alpha = 0.8f; // 透明度
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
        // 表示水印图片的位置
        g.drawImage(img, 380, 580, 220, 220, null);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

        //完成模板修改
        g.dispose();

        String outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }


    /**
     * 督导员证合成方法-幼儿照护-产后恢复
     *
     * @Description:  督导员证合成方法 ,参数说明：背景图，学员姓名，学员图像， 身份证号码，证书编码，证书名称，有效日期，工作单位
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, cerName, effectiveDate]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-20
     */
    public static String overTraSupervisorExaAffImage(String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String effectiveDate,String workUnit,String electronicSeal) throws IOException {
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
        BufferedImage backgroundImage = resizeImage(705, 983, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(195, 268, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(255, 255, 255);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 33));
        //考生姓名
        g.drawString(stuName, 274, 738);
        g.setFont(new Font("黑体", 2, 40));
        //考生头像
        g.drawImage(stuImgs, 255, 424, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 25));
        //身份证
        g.drawString(idCard, 254, 797);
        //证书编号
        g.drawString(cerNumber, 254, 837);

        //有效日期
        g.drawString(effectiveDate, 254, 875);
        if(workUnit.length()>16) {
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 20));
            //工作单位
            g.drawString(workUnit.substring(0,16), 254, 908);
            g.drawString(workUnit.substring(16,workUnit.length()), 254, 928);
        }else{
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 21));
            //工作单位
            g.drawString(workUnit, 254, 910);
        }
        //电子公章，以水印的形式插入
        //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
        ImageIcon imgIcon = new ImageIcon(electronicSeal);
        //得到Image对象。
        Image img = imgIcon.getImage();
        float alpha = 0.8f; // 透明度
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
        // 表示水印图片的位置
        g.drawImage(img, 380, 580, 220, 220, null);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

        //完成模板修改
        g.dispose();

        String outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }



    /**
     * 考试证书照片合成方法
     *
     * @Description: 考试证书照片合成方法，参数：合成类型（0带公章，1不带公章），背景图路径，考生姓名，考生头像图路径，身份证号码，证书编号，发证时间，考试年份，考试月份，证书等级中文，
     * 发证机构公章图路径，机构负责人签章图路径，考核点签章图路径
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, issueDate, examinYear, examinMath, cerLevelC, electronicSeal, orgPrincipalImg, assPointPrincipalImg]
     * @return: void
     * @Author: kl
     * @Date: 2020-06-16
     */
    public static String overlapImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String issueDate, String examinYear, String examinMath,
                                      String cerLevelC, String electronicSeal, String orgPrincipalImg, String assPointPrincipalImg) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(120, 160, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 24));
        if (counthanzi(stuName) == 2) {
            //考生姓名
            g.drawString(stuName, 890, 420);
            //考生姓名拼音
            g.drawString(getUpEname(stuName), 863, 460);
        } else if (counthanzi(stuName) == 3) {
            //考生姓名
            g.drawString(stuName, 880, 420);
            //考生姓名拼音
            g.drawString(getUpEname(stuName), 845, 460);
        } else {
            //考生姓名
            g.drawString(stuName, 866, 420);
            //考生姓名拼音
            g.drawString(getUpEname(stuName), 838, 460);
        }

        //考生头像
        g.drawImage(stuImgs, 858, 220, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 20));
        //身份证
        g.drawString(idCard, 295, 463);
        //证书编号
        g.drawString(cerNumber, 295, 513);
        //发证日期
        g.drawString(issueDate, 295, 622);

        if(type == 0) {
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 320, 515, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //考试年份（中文部分）
        g.drawString(examinYear, 213, 240);
        //考试月份（中文部分）
        g.drawString(examinMath, 295, 240);
        //认证批次对应的证书等级（中文部分）
        g.drawString(cerLevelC, 445, 273);

        g.setFont(new Font("Arial", Font.ITALIC + Font.BOLD, 14));
        //初级：Primary    中级：Intermediate    高级：Advanced
        if (cerLevelC.equals("初级")) {
            //认证批次对应的证书等级（英文部分）
            g.drawString("Primary", 329, 370);
        } else if (cerLevelC.equals("中级")) {
            //认证批次对应的证书等级（英文部分）
            g.drawString("Intermediate", 315, 370);
        } else {
            //认证批次对应的证书等级（英文部分）
            g.drawString("Advanced", 323, 370);
        }

        if (examinMath.equals("1")) {
            g.drawString("January" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("2")) {
            g.drawString("February" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("3")) {
            g.drawString("March" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("4")) {
            g.drawString("April" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("5")) {
            g.drawString("May" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("6")) {
            g.drawString("June" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("7")) {
            g.drawString("July" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("8")) {
            g.drawString("August" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("9")) {
            g.drawString("September" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("10")) {
            g.drawString("October" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else if (examinMath.equals("11")) {
            g.drawString("November" + " " + examinYear, 725, 338);//考试年月（英文部分）
        } else {
            g.drawString("December" + " " + examinYear, 725, 338);//考试年月（英文部分）
        }

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/cerSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/cerSynthesisNoSale/" + stuName + cerNumber + ".png";
        }
        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 重新设置图片大小
     *
     * @return      
     * @param width
     * @param height
     * @param bufferedImage
     */
    private static BufferedImage resizeImage(int width, int height, BufferedImage bufferedImage) {
        BufferedImage newBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        newBufferedImage.getGraphics().drawImage(bufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
        return newBufferedImage;
    }

    //统计汉字个数的方法
    public static int counthanzi(String text) {
        int amount = 0;
        for (int i = 0; i < text.length(); i++) {
            boolean matches = Pattern.matches("^[\u4E00-\u9Fa5]{0,}$", text.charAt(i) + "");
            if (matches) {
                amount++;
            }
        }
        return amount;
    }


    /**
     * 种子师资证合成方法-幼儿照护
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String seedOverTrainingImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                               String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 18));
        int a = 680-counthanzi(stuName)*18;
        g.drawString(stuName, a, 230);

        //证书文字-培训年份
        g.drawString(traYear, 780, 232);
        //证书文字-培训月份
        g.drawString(traMath, 860, 232);
        //证书文字-培训日期
        g.drawString(traDay, 918, 232);
        //证书文字-培训结束月份
        g.drawString(cerMath, 618, 269);
        //证书文字-培训结束日期
        g.drawString(cerDay, 676, 269);
        //考核期数
        g.drawString(numPeriods, 940, 303);
        //培训章节数（学时）
        g.drawString(trainingNumber, 690, 340);

        //考生头像
        g.drawImage(stuImgs, 232, 322, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 18));
        //身份证
        g.drawString(idCard, 221, 600);
        //证书编号
        g.drawString(cerNumber, 221, 637);
        //工作单位
        g.drawString(workUnit, 221, 676);

        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));
        //证书落笔-培训年份
        g.drawString(cerYear, 718, 673);
        //证书落笔-培训月份
        g.drawString(cerMath, 792, 674);
        //证书落笔-培训日期
        g.drawString(cerDay, 843, 674);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
            // outPutPath = ValuesUtil.localUrl + "/upload/2023706/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
            // outPutPath = ValuesUtil.localUrl + "/upload/2023706/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 公益师资证合成方法-幼儿照护及产后恢复
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String freeOverTrainingImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                               String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 24));
        int a = 225-counthanzi(stuName)*18;
        g.drawString(stuName, a, 355);

        //证书文字-培训年份
        g.drawString(traYear, 340, 355);
        //证书文字-培训月份
        g.drawString(traMath, 448, 355);
        //证书文字-培训日期
        g.drawString(traDay, 523, 355);
        //证书文字-培训结束月份
        g.drawString(cerMath, 630, 355);
        //证书文字-培训结束日期
        g.drawString(cerDay, 702, 355);
        //培训章节数（学时）
        g.drawString(trainingNumber, 872, 397);

        g.setFont(new Font("黑体", Font.BOLD, 18));
        //身份证
        g.drawString(idCard, 462, 493);
        //证书编号
        g.drawString(cerNumber, 462, 525);
        //工作单位
        g.drawString(workUnit, 462, 555);

        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));
        //证书落笔-培训年份
        g.drawString(cerYear, 465, 660);
        //证书落笔-培训月份
        g.drawString(cerMath, 541, 660);
        //证书落笔-培训日期
        g.drawString(cerDay, 593, 660);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 公益师资证合成方法-幼儿照护、产后恢复、医养个案管理、健康财富规划
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String OtherOverTrainingImageJk(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                                  String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(103, 104, 106);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", 0, 19));
        int a = 224-counthanzi(stuName)*18;
        g.drawString(stuName, a, 356);


        //培训章节数（学时）
        g.drawString(trainingNumber, 888, 355);

        g.setFont(new Font("微软雅黑", 0, 17));
        //证书编号
        g.drawString(cerNumber, 240, 593);




        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 公益师资证合成方法-幼儿照护、产后恢复、医养个案管理、健康财富规划
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String freeOverTrainingImageAll(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                                  String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 24));
        int a = 220-counthanzi(stuName)*18;
        g.drawString(stuName, a, 363);

        //证书文字-培训年份
        g.drawString(traYear, 340, 363);
        //证书文字-培训月份
        g.drawString(traMath, 446, 363);
        //证书文字-培训日期
        g.drawString(traDay, 519, 363);
        //证书文字-培训结束月份
        g.drawString(cerMath, 621, 363);
        //证书文字-培训结束日期
        g.drawString(cerDay, 695, 363);
        //培训章节数（学时）
        g.drawString(trainingNumber, 382, 449);

        g.setFont(new Font("黑体", Font.BOLD, 18));
        //身份证
        g.drawString(idCard, 462, 508);
        //证书编号
        g.drawString(cerNumber, 462, 546);
        //工作单位
        g.drawString(workUnit, 462, 586);


        //电子公章，以水印的形式插入
        //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
        ImageIcon imgIcon = new ImageIcon(electronicSeal);
        //得到Image对象。
        Image img = imgIcon.getImage();
        float alpha = 1.0f; // 透明度
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
        // 表示水印图片的位置
        g.drawImage(img, 220, 503, 177, 177, null);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

        g.setFont(new Font("黑体", Font.BOLD, 19));
        //证书落笔-培训年份
        g.drawString(cerYear, 466, 706);
        //证书落笔-培训月份
        g.drawString(cerMath, 547, 706);
        //证书落笔-培训日期
        g.drawString(cerDay, 605, 706);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 优秀学员证合成方法-幼儿照护
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String fineStudentTrainingImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                                  String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 28));
        int a = 280-counthanzi(stuName)*18;
        g.drawString(stuName, a, 340);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }
        g.setFont(new Font("微软雅黑", Font.BOLD, 20));
        //证书落笔-培训年份
        g.drawString(cerYear, 804, 688);
        //证书落笔-培训月份
        g.drawString(cerMath, 878, 688);
        //证书落笔-培训日期
        //g.drawString(cerDay, 843, 674);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }
    /**
     * 师资证合成方法-幼儿照护
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String overTrainingImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                           String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit,int grade ) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(144, 192, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 18));
        int a = 690-counthanzi(stuName)*18;
        g.drawString(stuName, a, 230);

        //证书文字-培训年份
        g.drawString(traYear, 780, 232);
        //证书文字-培训月份
        g.drawString(traMath, 862, 232);
        //证书文字-培训日期
        g.drawString(traDay, 919, 232);
        //证书文字-培训结束月份
        g.drawString(cerMath, 618, 269);
        //证书文字-培训结束日期
        g.drawString(cerDay, 676, 269);
        if(grade==0) {
            //考核期数
            g.drawString(numPeriods, 902, 303);
            //培训章节数（学时）
            g.drawString(trainingNumber, 674, 340);
        }else{
            //考核期数
            g.drawString(numPeriods, 937, 305);
            //培训章节数（学时）
            g.drawString(trainingNumber, 680, 342);
        }

        //考生头像
        g.drawImage(stuImgs, 242, 342, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 18));
        //身份证
        g.drawString(idCard, 230, 600);
        //证书编号
        g.drawString(cerNumber, 230, 637);
        //工作单位
        g.drawString(workUnit, 230, 676);

        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));
        //证书落笔-培训年份
        g.drawString(cerYear, 715, 674);
        //证书落笔-培训月份
        g.drawString(cerMath, 790, 673);
        //证书落笔-培训日期
        g.drawString(cerDay, 838, 672);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 师资证合成方法-产后恢复
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String overTrainingImageRecovery(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                                   String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit,int grade ) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(144, 192, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 18));
        int a = 690-counthanzi(stuName)*18;
        g.drawString(stuName, a, 230);
//        if (counthanzi(stuName) == 2) {
//            //考生姓名
//            g.drawString(stuName, 682, 230);
//        } else if (counthanzi(stuName) == 3) {
//            //考生姓名
//            g.drawString(stuName, 672, 230);
//        } else {
//            //考生姓名
//            g.drawString(stuName, 662, 230);
//        }

        //证书文字-培训年份
        g.drawString(traYear, 785, 232);
        //证书文字-培训月份
        g.drawString(traMath, 862, 232);
        //证书文字-培训日期
        g.drawString(traDay, 919, 232);
        //证书文字-培训结束月份
        g.drawString(cerMath, 618, 269);
        //证书文字-培训结束日期
        g.drawString(cerDay, 676, 269);
        if(grade==0) {
            //考核期数
            g.drawString(numPeriods, 902, 303);
            //培训章节数（学时）
            g.drawString(trainingNumber, 674, 340);
        }else{
            //考核期数
            g.drawString(numPeriods, 934, 303);
            //培训章节数（学时）
            g.drawString(trainingNumber, 685, 340);
        }

        //考生头像
        g.drawImage(stuImgs, 242, 342, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 18));
        //身份证
        g.drawString(idCard, 230, 600);
        //证书编号
        g.drawString(cerNumber, 230, 637);
        //工作单位
        g.drawString(workUnit, 230, 676);

        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));
        //证书落笔-培训年份
        g.drawString(cerYear, 715, 674);
        //证书落笔-培训月份
        g.drawString(cerMath, 790, 673);
        //证书落笔-培训日期
        g.drawString(cerDay, 838, 672);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }


    /**
     * 考务技术员结业证合成方法-幼儿照护-产后恢复
     *
     * @Description: 考务技术员结业证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String overTraAraGradiningImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                                  String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(120, 160, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 18));
        //考生姓名
        int a = 714-counthanzi(stuName)*18;
        g.drawString(stuName, a, 231);
//        if (counthanzi(stuName) == 2) {
//            //考生姓名
//
//        } else if (counthanzi(stuName) == 3) {
//            //考生姓名
//            g.drawString(stuName, 684, 231);
//        } else {
//            //考生姓名
//            g.drawString(stuName, 674, 231);
//        }

        //证书文字-培训年份
        g.drawString(traYear, 790, 231);
        //证书文字-培训月份
        g.drawString(traMath, 866, 231);
        //证书文字-培训日期
        g.drawString(traDay, 918, 231);
        //考核期数
        g.drawString(numPeriods, 893, 303);
        //培训章节数（学时）
        g.drawString(trainingNumber, 715, 340);

        //考生头像
        g.drawImage(stuImgs, 254, 374, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 20));
        //身份证
        g.drawString(idCard, 270, 613);
        //证书编号
        g.drawString(cerNumber, 270, 648);
        //工作单位
        g.drawString(workUnit, 270, 683);

        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }

        //证书落笔-培训年份
        g.drawString(cerYear, 708, 671);
        //证书落笔-培训月份
        g.drawString(cerMath, 782, 671);
        //证书落笔-培训日期
        g.drawString(cerDay, 831, 671);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }



    /**
     * 督导员结业证合成方法-幼儿照护
     *
     * @Description: 督导员结业证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String overTraSupervisorGradiningImage(int type,String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String numPeriods, String trainingNumber,
                                                         String traYear, String traMath, String traDay,String cerYear, String cerMath, String cerDay, String electronicSeal,String workUnit) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        System.out.println(backgroundPath);
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(120, 160, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 18));
        int a = 714-counthanzi(stuName)*18;
        g.drawString(stuName, a, 231);
//        if (counthanzi(stuName) == 2) {
//            //考生姓名
//            g.drawString(stuName, 694, 231);
//        } else if (counthanzi(stuName) == 3) {
//            //考生姓名
//            g.drawString(stuName, 684, 231);
//        } else {
//            //考生姓名
//            g.drawString(stuName, 674, 231);
//        }

        //证书文字-培训年份
        g.drawString(traYear, 789, 231);
        //证书文字-培训月份
        g.drawString(traMath, 866, 231);
        //证书文字-培训日期
        g.drawString(traDay, 918, 231);
        //考核期数
        g.drawString(numPeriods, 862, 303);
        //培训章节数（学时）
        g.drawString(trainingNumber, 710, 340);

        //考生头像
        g.drawImage(stuImgs, 254, 374, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 19));

        //身份证
        g.drawString(idCard, 270, 613);
        //证书编号
        g.drawString(cerNumber, 270, 648);
        //工作单位
        g.drawString(workUnit, 270, 683);

        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }

        //证书落笔-培训年份
        g.drawString(cerYear, 708, 671);
        //证书落笔-培训月份
        g.drawString(cerMath, 782, 671);
        //证书落笔-培训日期
        g.drawString(cerDay, 831, 671);

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }


    /**
     * 考评员证合成方法-幼儿照护
     *
     * @Description:  考评员培训照片合成方法 ,参数说明：背景图，学员姓名，学员图像， 身份证号码，证书编码，证书名称，有效日期，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, cerName, effectiveDate]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-20
     *
     *
     *
     */
    public static String overTraExaImage(String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String effectiveDate,String workUnit,int grade,String electronicSeal) throws IOException {
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
        BufferedImage backgroundImage = resizeImage(705, 983, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(195, 268, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(0, 0, 0);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 33));
        //考生姓名
        g.drawString(stuName, 274, 740);
        g.setFont(new Font("黑体", 2, 40));
        //考生头像
        g.drawImage(stuImgs, 253, 422, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 25));
        //身份证
        g.drawString(idCard, 254, 797);
        //证书编号
        g.drawString(cerNumber, 254, 837);

        //有效日期
        g.drawString(effectiveDate, 254, 875);
        if(workUnit.length()>16) {
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 20));
            //工作单位
            g.drawString(workUnit.substring(0,16), 254, 910);
            g.drawString(workUnit.substring(16,workUnit.length()), 254, 930);
        }else{
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 21));
            //工作单位
            g.drawString(workUnit, 254, 912);
        }
        //电子公章，以水印的形式插入
        //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
        ImageIcon imgIcon = new ImageIcon(electronicSeal);
        //得到Image对象。
        Image img = imgIcon.getImage();
        float alpha = 0.8f; // 透明度
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
        // 表示水印图片的位置
        g.drawImage(img, 380, 580, 220, 220, null);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

        //完成模板修改
        g.dispose();

        String outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    /**
     * 考评员证合成方法-产后恢复
     *
     * @Description:  考评员培训照片合成方法 ,参数说明：背景图，学员姓名，学员图像， 身份证号码，证书编码，证书名称，有效日期，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, cerName, effectiveDate]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-20
     *
     *
     *
     */
    public static String overTraExaImageRecovery(String backgroundPath, String stuName, String stuImg, String idCard, String cerNumber, String effectiveDate,String workUnit,int grade,String electronicSeal) throws IOException {
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
        BufferedImage backgroundImage = resizeImage(705, 983, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(195, 268, ImageIO.read(new File(stuImg)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(0, 0, 0);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 33));
        //考生姓名
        g.drawString(stuName, 274, 740);
        g.setFont(new Font("黑体", 2, 40));
        //考生头像
        g.drawImage(stuImgs, 253, 422, stuImgs.getWidth(), stuImgs.getHeight(), null);

        g.setFont(new Font("黑体", Font.BOLD, 25));
        //身份证
        g.drawString(idCard, 254, 797);
        //证书编号
        g.drawString(cerNumber, 254, 837);

        //有效日期
        g.drawString(effectiveDate, 254, 875);
        if(workUnit.length()>16) {
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 20));
            //工作单位
            g.drawString(workUnit.substring(0,16), 254, 910);
            g.drawString(workUnit.substring(16,workUnit.length()), 254, 930);
        }else{
            g.setFont(new Font("方正粗黑宋简体", Font.BOLD, 21));
            //工作单位
            g.drawString(workUnit, 254, 912);
        }
        //电子公章，以水印的形式插入
        //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
        ImageIcon imgIcon = new ImageIcon(electronicSeal);
        //得到Image对象。
        Image img = imgIcon.getImage();
        float alpha = 0.8f; // 透明度
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
        // 表示水印图片的位置
        g.drawImage(img, 380, 580, 220, 220, null);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

        //完成模板修改
        g.dispose();

        String outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }





//    public static void main(String[] args) throws IOException {
//        prizeImage("D:/upload/yxpxYz.jpg","孟智超","JZ52432211090002","2022","04","07");
//    }






    /**
     * 优秀学员证合成方法-幼儿照护
     *
     * @Description: 师资证合成方法，参数说明：合成类型（0带公章，1不带公章），背景图，学员姓名，学员图像， 身份证号码，证书编码，考核期数，培训章节数（学时），
     * 培训年份，培训月份，培训日期，获证年份，获证年份，获证年份，电子公章，工作单位，级别
     * @Param: [backgroundPath, stuName, stuImg, idCard, cerNumber, trainingName, trainingNumber, trainingYear, trainingMath, trainingDay, cerName, electronicSeal]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String prizeImage(String backgroundPath, String stuName, String cerNumber,String year,String math) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(40, 40, 40);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 28));
        int a = 220-counthanzi(stuName)*22;
        g.drawString(stuName, a, 296);


        g.drawString(year, 240, 352);

        g.drawString(year, 740, 682);
        g.drawString(math, 834, 682);


        //完成模板修改
        g.dispose();

        String outPutPath;
        outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        System.out.println("生成后的路径："+outPutPath);
        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }






    /**
     * 优秀学员证合成方法-金职大讲堂
     *
     * @Description: 金职大讲堂优秀学员证合成方法，参数说明：
     * 合成类型（0带公章，1不带公章），背景图，学员姓名，证书编号，电子印章地址，年，月，日，第几期
     * @Param: [type, backgroundPath, stuName, cerNumber, electronicSeal, traYear, traMath, traDay, tranche]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     */
    public static String prizeImageYXXY(int type,String backgroundPath, String stuName, String cerNumber,String electronicSeal,String traYear, String traMath, String traDay,String tranche) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 380-counthanzi(stuName)*22;
        g.drawString(stuName, a, 340);



        g.drawString(tranche, 215, 427);

        g.drawString(traYear, 785, 685);
        //证书文字-培训月份
        g.drawString(traMath, 878, 685);
        //证书文字-培训日期
        g.drawString(traDay, 931, 685);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 770, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }



    /**
     * 优秀企业证合成方法-金职大讲堂
     *
     * @Description: 金职大讲堂优秀学员证合成方法，参数说明：
     * 合成类型（0带公章，1不带公章），背景图，公司，证书编号，电子印章地址，年，月，日，第几期
     * @Param: [type, backgroundPath, gsName, cerNumber, electronicSeal, traYear, traMath, traDay, tranche]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     *
     */
    public static String prizeImageYXZZDW(int type,String backgroundPath, String gsName, String cerNumber,String electronicSeal,String traYear, String traMath, String traDay,String tranche) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 620-counthanzi(gsName)*22;
        g.drawString(gsName, a, 340);



        g.drawString(tranche, 215, 427);

//        g.drawString(traYear, 785, 685);
        g.drawString(traYear, 242, 351);
        //证书文字-培训月份
        g.drawString(traMath, 878, 685);
        //证书文字-培训日期
        g.drawString(traDay, 931, 685);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 770, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + gsName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + gsName + cerNumber + ".png";
        }


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }





    /**
     * 结业证书合成方法-金职大讲堂
     *
     * @Description: 金职大讲堂优秀学员证合成方法，参数说明：
     * 合成类型（0带公章，1不带公章），背景图，姓名，证书编号，电子印章地址，年，月，日，第几期
     * @Param: [type, backgroundPath, stuName, cerNumber, electronicSeal, traYear, traMath, traDay, tranche]
     * @return: java.lang.String
     * @Author: kl
     * @Date: 2020-07-17
     *
     */
    public static String prizeImageJYZS(int type,String backgroundPath, String stuName, String cerNumber,String electronicSeal,String traYear, String traMath, String traDay,String tranche,String stuCard,String stuUnit,String period,String exTraYear, String exTraMath) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 230-counthanzi(stuName)*22;
        g.drawString(stuName, a, 357);

        //第几期
        g.drawString(tranche, 365, 400);
        //年份
        g.drawString(exTraYear, 334, 357);
        //证书文字-培训月份
        g.drawString(exTraMath, 436, 357);

        //年度
        g.drawString(exTraYear, 217, 400);
        //学时
        g.drawString(period, 778, 400);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        g.drawString(traYear, 469, 656);
        //证书文字-培训月份
        g.drawString(traMath, 539, 656);
        //证书文字-培训日期
        g.drawString(traDay, 589, 656);

        //身份证号
        g.drawString(stuCard, 465, 490);
        //证书编号
        g.drawString(cerNumber, 465, 522);
        //工作单位
        g.drawString(stuUnit, 465, 553);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }






















































//        public static void main(String[] args) throws IOException {
//
//        String zhengshumuban = "D:/upload/yrzh_sz_zj.jpg"; //证书模板位置
//
//
//        String xingming = "茹克亚古丽·买买提"; //姓名
//        String shenfenzhenghao = "411424198506241642"; //身份证号
//        String zhengshubianhao = "JZ20412008010093"; //证书编号
//
//
//        String kaishinian = "2022"; //培训开始日期
//        String kaishiyue = "11"; //培训开始日期
//        String kaishiri = "11"; //培训开始日期
//        String jieshunian = "2023"; //培训截止日期
//        String jieshuyue = "09"; //培训截止日期
//        String jieshuri = "23"; //培训截止日期
//
//        String shijianxiangmu = "这是实践项目"; //实践项目
//        String xianxiaxueshi = "5"; //线下学时
//        String xianshangxueshi = "10"; //线上学时
//        String qitaxueshi = "20"; //其它学时
//
//        String huozhengriqinian = "2023"; //获证日期年
//        String huozhengriqiyue = "09"; //获证日期月
//        String huozhengriqiri = "23"; //获证日期日
//
//        String dianzigongzhang = "D:/upload/zyjygz.png"; //公章
//        prizeImageSHiZi4(0,zhengshumuban,xingming,shenfenzhenghao,zhengshubianhao,kaishinian,kaishiyue,kaishiri,jieshunian,jieshuyue ,xianxiaxueshi,xianshangxueshi,qitaxueshi,huozhengriqinian,huozhengriqiyue,huozhengriqiri);
//    }




    /**
     * 1+X产后恢复师资培训证书（中级）,+X产后恢复师资培训证书（高级）,+X幼儿照护师资培训证书（中级）,+X幼儿照护师资培训证书（高级）
     *
     * @Description: 参数说明：
     *
     */
    public static String prizeImageSHiZi4(int type,String backgroundPath, String stuName, String stuImg,String cerNumber,String electronicSeal,String traYear, String traMath, String traDay,String tranche,String stuCard,String stuUnit,String period,String cerYear, String cerMath,String cerDay) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        System.out.println("幼儿照护师资培训证书模板路径++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"+backgroundPath);
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("黑体", Font.BOLD, 18));

        if (stuName.length()<9&&stuName.length()>6){
            int a = 767-counthanzi(stuName)*22 ;
            g.drawString(stuName, a, 240);
        }else if (stuName.length()>8){
            int a = 770-counthanzi(stuName)*22 ;
            g.drawString(stuName, a, 240);
        }else {
            int a = 720-counthanzi(stuName)*22;
            g.drawString(stuName, a, 240);
        }


        //第几期
        g.drawString(tranche, 735, 315);
        //培训日期年份
        g.drawString(traYear, 799, 315);
        //培训日期月份
        g.drawString(traMath, 884, 315);
        //培训日期日份
        g.drawString(traDay, 931, 315);
        //培训截止月份
        g.drawString(cerMath, 610, 353);
        //培训截止日份
        g.drawString(cerDay, 658, 353);
        //学时
        g.drawString(period,831,353);

        //考生头像
        g.drawImage(stuImgs, 243, 335, 139, 197, null);

        g.setFont(new Font("黑体", Font.BOLD, 18));
        //身份证
        g.drawString(stuCard, 230, 600);
        //证书编号
        g.drawString(cerNumber, 230, 637);
        //工作单位
        g.drawString(stuUnit, 230, 676);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //证书落笔-培训年份
        g.drawString(cerYear, 715, 674);
        //证书落笔-培训月份
        g.drawString(cerMath, 790, 673);
        //证书落笔-培训日期
        g.drawString(cerDay, 838, 672);


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }
        System.out.println("生成路径为+++++++++++++++++++++++++++++++++++++++++++++++"+outPutPath);
        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }




    /**
     * 素质提高计划(幼儿照护1+X中级证书)
     *  是否带章，证书模板，名字，证书编号，公章地址，培训年份，培训月份，身份证号，工作单位，学时，证书落款年份，证书落款月份，证书落款日
     */
    public static String prizeImageSZTGJH(int type,String backgroundPath, String stuName, String cerNumber,String electronicSeal,String traYear, String traMath,String stuCard,String stuUnit,String period,String exTraYear, String exTraMath,String exTraDay) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 220-counthanzi(stuName)*22;
        g.drawString(stuName, a, 348);


        //年份
        g.drawString(traYear, 317, 348);
        //证书文字-培训月份
        g.drawString(traMath, 415, 348);


        //学时
        g.drawString(period, 195, 435);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        //落款日期
        g.drawString(exTraYear, 469, 656);
        //证书文字-培训月份
        g.drawString(exTraMath, 539, 656);
        //日
        g.drawString(exTraDay, 600, 656);


        //身份证号
        g.drawString(stuCard, 465, 496);
        //证书编号
        g.drawString(cerNumber, 465, 528);
        //工作单位
        g.drawString(stuUnit, 465, 558);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }






//    public static void main(String[] args) throws IOException {
//
//        String zhengshumuban = "D:/upload/sjxmmub.png"; //证书模板位置
//
//
//        String xingming = "李小璐"; //姓名
//        String shenfenzhenghao = "411424198506241642"; //身份证号
//        String zhengshubianhao = "JZ20412008010093"; //证书编号
//
//
//        String kaishinian = "2022"; //培训开始日期
//        String kaishiyue = "11"; //培训开始日期
//        String kaishiri = "11"; //培训开始日期
//        String jieshunian = "2023"; //培训截止日期
//        String jieshuyue = "09"; //培训截止日期
//        String jieshuri = "23"; //培训截止日期
//
//        String shijianxiangmu = "这是实践项目"; //实践项目
//        String xianxiaxueshi = "5"; //线下学时
//        String xianshangxueshi = "10"; //线上学时
//        String qitaxueshi = "20"; //其它学时
//
//        String huozhengriqinian = "2023"; //获证日期年
//        String huozhengriqiyue = "09"; //获证日期月
//        String huozhengriqiri = "23"; //获证日期日
//
//        String dianzigongzhang = "D:/upload/zyjygz.png"; //公章
//
//
//        prizeImageSJXMJYZS(0,zhengshumuban,xingming,shenfenzhenghao,zhengshubianhao,kaishinian,kaishiyue,kaishiri,jieshunian,jieshuyue,
//                jieshuri,shijianxiangmu,xianxiaxueshi,xianshangxueshi,qitaxueshi,huozhengriqinian,huozhengriqiyue,huozhengriqiri,dianzigongzhang);
//    }
//
//




    public static String prizeImageSJXMJYZS(int type,String zhengshumuban, String xingming, String shenfenzhenghao,String zhengshubianhao,String kaishinian, String kaishiyue,String kaishiri,String jieshunian,String jieshuyue,
                                            String jieshuri,String shijianxiangmu, String xianxiaxueshi,String xianshangxueshi,String qitaxueshi,String huozhengriqinian,String huozhengriqiyue,String huozhengriqiri,String dianzigongzhang) throws IOException {

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(zhengshumuban)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();
        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 290-counthanzi(xingming)*22;
        g.drawString(xingming, a, 335);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));

        //开始时间and结束时间
        g.drawString(kaishinian, 803, 335);
        g.drawString(kaishiyue, 875, 335);
        g.drawString(kaishiri, 922, 335);

        g.drawString(jieshunian, 200, 377);
        g.drawString(jieshuyue, 278, 377);
        g.drawString(jieshuri, 327, 377);


        //实践项目
        g.drawString(shijianxiangmu, 430, 377);

        //线下学时
        g.drawString(xianxiaxueshi, 410, 420);

        //线上学时
        g.drawString(xianshangxueshi, 610, 420);

        //其它学时
        g.drawString(qitaxueshi, 765, 420);



        //落款日期
        g.drawString(huozhengriqinian, 635, 641);
        //证书文字-培训月份
        g.drawString(huozhengriqiyue, 704, 641);
        //日
        g.drawString(huozhengriqiri, 754, 641);




        //身份证号
        g.drawString(shenfenzhenghao, 530, 335);

        //证书编号
        g.drawString(zhengshubianhao, 805, 127);

        if(type == 0){
            System.out.println("进入电子公章");
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(dianzigongzhang);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 610, 500,null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + xingming + zhengshubianhao + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + xingming + dianzigongzhang + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }



































    /**
     * 婴幼儿教学能力提升证书
     *  是否带章，证书模板，名字，证书编号，公章地址，培训年份，培训月份，身份证号，工作单位，学时，证书落款年份，证书落款月份，证书落款日
     */
    public static String prizeImageYYJXNLTS(int type,String backgroundPath, String stuName, String cerNumber,String electronicSeal,String traYear, String traMath,String traDay,String stuCard,String stuUnit,String period,String exTraYear, String exTraMath,String exTraDay) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 280-counthanzi(stuName)*22;
        g.drawString(stuName, a, 300);


        //年份
        g.drawString(traYear, 376, 302);
        //证书文字-培训月份
        g.drawString(traMath, 464, 302);
        //日
        g.drawString(traDay, 519, 302);
        //落款日期 年
        g.drawString(exTraYear, 595, 302);
        //落款日期 月
        g.drawString(exTraMath, 681, 302);
        //落款日期 日
        g.drawString(exTraDay, 736, 302);


        //学时
        g.drawString(period, 708, 344);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        //落款日期
        g.drawString(exTraYear, 485, 678);
        //证书文字-培训月份
        g.drawString(exTraMath, 558, 678);
        //日
        g.drawString(exTraDay, 613, 678);


        //身份证号
        g.drawString(stuCard, 490, 443);
        //证书编号
        g.drawString(cerNumber, 490, 484);
        //工作单位
        g.drawString(stuUnit, 490, 528);


        if(type == 0){
            System.out.println("进入电子公章");
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 570, 158, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }







    /**
     * 教学能力比赛研修班证书
     *  是否带章，证书模板，名字，证书编号，公章地址，培训年份，培训月份，身份证号，工作单位，学时，证书落款年份，证书落款月份，证书落款日，证书图片
     */
    public static String prizeImagBSBSPXB(int type,String backgroundPath, String stuName, String cerNumber,
                                            String electronicSeal,String traYear, String traMath,String traDay,String stuCard
            ,String stuUnit,String period,String exTraYear, String exTraMath,String exTraDay) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 217-counthanzi(stuName)*22;

        g.drawString(stuName, a, 355);

        //年份
        g.drawString(traYear, 315, 355);
        //证书文字-培训月份
        g.drawString(traMath, 419, 355);

        //学时
        g.drawString(period, 493, 397);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        //落款日期
        g.drawString(exTraYear, 495, 656);
        //证书文字-培训月份
        g.drawString(exTraMath, 556, 656);
        //日
        g.drawString(exTraDay, 596, 656);


        //身份证号
        g.drawString(stuCard, 462, 490);
        //证书编号
        g.drawString(cerNumber, 462, 523);
        //工作单位
        g.drawString(stuUnit, 462, 555);


        if(type == 0){
            System.out.println("进入电子公章");
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 560, 158, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }


















    /**
     * 教学能力比赛研修班证书
     *  是否带章，证书模板，名字，证书编号，公章地址，培训年份，培训月份，身份证号，工作单位，学时，证书落款年份，证书落款月份，证书落款日，证书图片
     */
    public static String prizeImagJXNLBSYXB(int type,String backgroundPath, String stuName, String cerNumber,
                                            String electronicSeal,String traYear, String traMath,String traDay,String stuCard
            ,String stuUnit,String period,String exTraYear, String exTraMath,String exTraDay) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 230-counthanzi(stuName)*22;

        g.drawString(stuName, a, 355);

        //年份
        g.drawString(traYear, 331, 355);
        //证书文字-培训月份
        g.drawString(traMath, 424, 355);

        //学时
        g.drawString(period, 368, 397);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        //落款日期
        g.drawString(exTraYear, 468, 656);
        //证书文字-培训月份
        g.drawString(exTraMath, 536, 656);
        //日
        g.drawString(exTraDay, 589, 656);


        //身份证号
        g.drawString(stuCard, 462, 490);
        //证书编号
        g.drawString(cerNumber, 462, 523);
        //工作单位
        g.drawString(stuUnit, 462, 555);


        if(type == 0){
            System.out.println("进入电子公章");
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 560, 158, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }




















    /**
     * 教研能力提升证书
     *  是否带章，证书模板，名字，证书编号，公章地址，培训年份，培训月份，身份证号，工作单位，学时，证书落款年份，证书落款月份，证书落款日，证书图片
     */
    public static String prizeImagJYTSZS(int type,String backgroundPath, String stuName, String cerNumber,String electronicSeal,String traYear, String traMath,String traDay,String stuCard,String stuUnit,String period,String exTraYear, String exTraMath,String exTraDay,String stuImg) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        BufferedImage stuImgs = resizeImage(120, 180, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 250-counthanzi(stuName)*22;

        g.drawString(stuName, a, 300);

        g.drawImage(stuImgs, 850, 100, 110, 157, null);

        //年份
        g.drawString(traYear, 336, 302);
        //证书文字-培训月份
        g.drawString(traMath, 420, 302);
        //日
        g.drawString(traDay, 467, 302);
        //落款日期 年
        g.drawString(exTraYear, 540, 302);
        //落款日期 月
        g.drawString(exTraMath, 625, 302);
        //落款日期 日
        g.drawString(exTraDay, 670, 302);


        //学时
        g.drawString(period, 710, 344);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        //落款日期
        g.drawString(exTraYear, 485, 678);
        //证书文字-培训月份
        g.drawString(exTraMath, 558, 678);
        //日
        g.drawString(exTraDay, 610, 678);


        //身份证号
        g.drawString(stuCard, 456, 443);
        //证书编号
        g.drawString(cerNumber, 456, 484);
        //工作单位
        g.drawString(stuUnit, 456, 528);


        if(type == 0){
            System.out.println("进入电子公章");
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 570, 158, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }











    /**
     * 家庭教育指导课程
     *  是否带章，证书模板，名字，证书编号，公章地址，培训年份，培训月份，身份证号，工作单位，学时，证书落款年份，证书落款月份，证书落款日，证书图片
     */
    public static String prizeImagJTJYZDKC(int type,String backgroundPath, String stuName, String cerNumber,String electronicSeal,String traYear, String traMath,String traDay,String stuCard,String stuUnit,String period,String exTraYear, String exTraMath,String exTraDay) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 25));
        int a = 280-counthanzi(stuName)*22;

        g.drawString(stuName, a, 300);


        //年份
        g.drawString(traYear, 473, 302);
        //证书文字-培训月份
        g.drawString(traMath, 575, 302);
        //日
        g.drawString(traDay, 637, 302);
        //落款日期 年
        g.drawString(exTraYear, 722, 302);
        //落款日期 月
        g.drawString(exTraMath, 823, 302);
        //落款日期 日
        g.drawString(exTraDay, 881, 302);


        //学时
        g.drawString(period, 629, 344);



        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        //落款日期
        g.drawString(exTraYear, 475, 678);
        //证书文字-培训月份
        g.drawString(exTraMath, 545, 678);
        //日
        g.drawString(exTraDay, 610, 678);


        //身份证号
        g.drawString(stuCard, 456, 443);
        //证书编号
        g.drawString(cerNumber, 456, 484);
        //工作单位
        g.drawString(stuUnit, 456, 528);


        if(type == 0){
            System.out.println("进入电子公章");
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 570, 158, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }











//    public static void main(String[] args) {
//        int electronicSealType = 0;
//        String backgroundPath = "D:/upload/chhf_khzd_pb.jpg";
//        String orgName = "甘肃有色冶金职业技术学院";
//        String s="";
//
//        String code = "88546";
//        String cerYear = "2022";
//        String cerMath = "11";
//        String electronicSeal = "D:/upload/jzgz.png";
//        try {
//            String chhfkhzdpb = yezhkhzdpb(electronicSealType, backgroundPath, orgName, code, cerYear, cerMath, electronicSeal, s);
//            System.out.println("url++++++++++++++++++++++++++++++++++++++"+chhfkhzdpb);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }


    public static int getX(String orgName){
        int x = 310;
        int dft = 10; //默认是十个字符
        //获取字符串长度
        int length = orgName.length();
        if (length == 14){
            x = 272;
        }else if (length == 13){
            x = 270;
        }else if (length == 12){
            x = 270;
        }else if (length == 11){
            x = 260;
        }else if (length == 10){
            x = 250;
        }
        else if (length > 14&&length<=32){
            x = 275;
        }else if (length>33){
            x = 290;
        }
        else {
            if (length > dft){
                length = length - dft;
                System.out.println("大于默认长度并相差+++++++++++++++++++++++++++++++++++++"+length);
                x  = x - (length * 28);
            }else if (length < dft){
                length = dft - length;
                System.out.println("小于默认长度并相差+++++++++++++++++++++++++++++++++++++"+length);
                x  = x + (length * 28);
            }
        }
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++X的值为:"+x);
        return x;
    }

//    public static void main(String[] args) {
//        String s="灵武市职业技术学校（灵武市职业技能培训学校、宁夏广播电视大学灵武市工作站）";
//        System.out.println("ssss="+ s.length());
//    }

    /**
     * @param electronicSealType 是否带印章
     * @param backgroundPath     证书模板路径
     * @param orgName            学校名称
     * @param code               站点编号
     * @param cerYear            生成年份
     * @param cerMath            生成月份
     * @param electronicSeal     印章路径
     * @param s
     * @return
     * @throws IOException
     */
    public static String chhfkhzdpb(int electronicSealType, String backgroundPath, String orgName, String code, String cerYear, String cerMath, String electronicSeal, String s) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("方正粗雅宋", Font.BOLD, 20));

        //站点编码
        g.drawString(code, 290, 625);
        //证书落笔-培训年份
        g.drawString(cerYear, 852, 652);
        //证书落笔-培训月份
        g.drawString(cerMath, 935, 652);

        if (orgName.length()>28){
            g.setFont(new Font("方正粗雅宋", Font.BOLD, 22));
        }else {
            g.setFont(new Font("方正粗雅宋", Font.BOLD, 50));
        }

//        //学校名称
        g.drawString(orgName, getX(orgName), 530);

        if(electronicSealType == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 755, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            System.out.println("进入带印章方法+++++++++++++++++++++++++++++++++++++++++++印章地址为"+electronicSeal);
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(electronicSealType == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + orgName + code + s+".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + orgName + code +s+ ".png";
        }
        System.out.println("最终路径++++++++++++++++++++++++++++++++++++++++++++"+outPutPath);

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));
        return outPutPath;
    }



    public static String yezhkhzdpb(int electronicSealType, String backgroundPath, String orgName, String code, String cerYear, String cerMath, String electronicSeal, String s) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(0, 0, 0);
        g.setColor(color);
        g.setFont(new Font("方正粗雅宋", Font.BOLD, 20));

        //站点编码
        g.drawString(code, 290, 625);
        //证书落笔-培训年份
        g.drawString(cerYear, 848, 652);
        //证书落笔-培训月份
        g.drawString(cerMath, 933, 652);


        if (orgName.length()>28){
            g.setFont(new Font("方正粗雅宋", Font.BOLD, 22));
        }else {
            g.setFont(new Font("方正粗雅宋", Font.BOLD, 50));
        }

//        //学校名称
        g.drawString(orgName, getX(orgName), 530);

        if(electronicSealType == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 755, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            System.out.println("进入带印章方法+++++++++++++++++++++++++++++++++++++++++++印章地址为"+electronicSeal);
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(electronicSealType == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + orgName + code +s+ ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + orgName + code +s+ ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));
        return outPutPath;
    }


    /**
     * 金砖志愿者证书
     */
    public static String prizeImagZYZFWZS(int electronicSealType,String backgroundPath,String stuName,String electronicSeal,String numPeriods,String cerYear,String cerMath,String cerDay,String cerNumber) throws IOException {
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
        BufferedImage backgroundImage = resizeImage(794, 1123, ImageIO.read(new File(backgroundPath)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();
        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("方正粗雅宋", Font.BOLD, 30));
        g.drawString(stuName, 190, 455);
        g.setFont(new Font("黑体", Font.BOLD, 20));

        //姓名
        g.drawString(stuName, 310, 721);
        //场次
        g.drawString(numPeriods, 228, 577);
        g.drawString(numPeriods+" Session", 535, 785);
        g.drawString(numPeriods, 450, 941);

        g.setFont(new Font("黑体", Font.BOLD, 16));
        //年份
        g.drawString(cerYear, 332, 962);
        //月份
        g.drawString(cerMath, 388, 962);
        //日份
        g.drawString(cerDay, 426, 962);
        g.setFont(new Font("方正粗雅宋", Font.BOLD, 50));

        if(electronicSealType == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 480, 755, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            System.out.println("进入带印章方法+++++++++++++++++++++++++++++++++++++++++++印章地址为"+electronicSeal);
        }
        g.setFont(new Font("黑体", Font.BOLD, 19));

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(electronicSealType == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber+ ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber+ ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));
        return outPutPath;
    }










//
//    public static void main(String[] args) throws IOException {
//        prizeImagCJRH(0,"D:/upload/ggtflsz.jpg","孟智超","12225555");
//    }





    public static String yxsx_sfkhzd_yxkh(String backgroundPath, String orgName, String cerYear, String cerMath, String s) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        g.setFont(new Font("方正粗雅宋", Font.BOLD, 20));

        //证书落笔-培训年份
        g.drawString(cerYear, 800, 652);
        //证书落笔-培训月份
        g.drawString(cerMath, 888, 652);

        if (orgName.length()>32){
            g.setFont(new Font("方正粗雅宋", Font.BOLD, 22));
        }else {
            g.setFont(new Font("方正粗雅宋", Font.BOLD, 30));
        }

        //学校名称
        g.drawString(orgName, getX(orgName), 275);

        g.setFont(new Font("方正粗雅宋", Font.BOLD, 37));

        //年份
        g.drawString("2024", 232, 349);
//        g.drawString(cerYear, 232, 349);

        //完成模板修改
        g.dispose();


        String outPutPath  = ValuesUtil.localUrl + "/upload/traSynthesis/" + orgName +s+ ".png";
        System.out.println(outPutPath);


        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));
        return outPutPath;
    }









    /**
     * 产教融合相关证书
     *  是否带章，证书模板，名字
     */
    public static String prizeImagCJRH(int type,String backgroundPath, String stuName,String cerNumber) throws IOException {

        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(55, 55, 55);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 25));
        int a = 360-counthanzi(stuName)*22;

        g.drawString(stuName, a, 355);

        //完成模板修改
        g.dispose();

        String outPutPath;
        //生成到那个路径下
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    //幼儿照护
    public static String prizeImage(String backgroundPath, String stuName, String cerNumber, String cerYear, String cerMath, String traYear,Integer type) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(40, 40, 40);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 29));
        int a = 220-counthanzi(stuName)*22;
        g.drawString(stuName, a, 296);
        if(backgroundPath.contains("yxpxYz")){
            //优秀培训教师的
            g.setFont(new Font("微软雅黑", Font.BOLD, 27));
            //年度日期：优秀培训教师的
            g.drawString("2024", 243, 353);
        }else {
            //特殊贡献奖的
            g.setFont(new Font("微软雅黑", Font.BOLD, 25));
            //年度日期：特殊贡献奖的
            g.drawString("2024", 240, 353);
        }


        g.setFont(new Font("微软雅黑", Font.BOLD, 23));
        if (type.equals(11)){
            //培训日期 优秀培训教师
            g.drawString(cerYear, 748, 679);
            g.drawString(cerMath, 838, 679);
        }if (type.equals(12)) {
            //培训日期
            g.drawString(cerYear, 749, 682);
            g.drawString(cerMath, 840, 682);
        }if (type.equals(13)){
            //培训日期 特殊贡献奖
            g.drawString(cerYear, 749, 679);
            g.drawString(cerMath, 840, 679);
        }



        //完成模板修改
        g.dispose();

        String outPutPath;
        outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        System.out.println("生成后的路径："+outPutPath);
        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    //产后恢复
    public static String prizeImage1(String backgroundPath, String stuName, String cerNumber, String cerYear, String cerMath, String traYear, Integer type) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));
        //BufferedImage stuImgs = resizeImage(164, 222, ImageIO.read(new File(stuImg)));
        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(40, 40, 40);
        g.setColor(color);
        g.setFont(new Font("微软雅黑", Font.BOLD, 29));
        int a = 220-counthanzi(stuName)*22;
        g.drawString(stuName, a, 290);
        if(backgroundPath.contains("yxpxYz")){
            //优秀培训教师的
            g.setFont(new Font("微软雅黑", Font.BOLD, 27));
            //年度日期：优秀培训教师的
            g.drawString(traYear, 243, 353);
        }else {
            //特殊贡献奖的
            g.setFont(new Font("微软雅黑", Font.BOLD, 25));
            //年度日期：特殊贡献奖的
            g.drawString(traYear, 240, 353);

        }

        g.setFont(new Font("微软雅黑", Font.BOLD, 23));
        if (type.equals(13)){
            //培训日期 特殊贡献奖
            g.drawString(cerYear, 738, 679);
            g.drawString(cerMath, 832, 679);
        }if (type.equals(12)) {
            //培训日期 优秀考务工作者
            g.drawString(cerYear, 738, 682);
            g.drawString(cerMath, 832, 682);
        }if (type.equals(11)){
            g.drawString(cerYear, 738, 677);
            g.drawString(cerMath, 832, 677);
        }

        //完成模板修改
        g.dispose();

        String outPutPath;
        outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";


        System.out.println("生成后的路径："+outPutPath);
        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }


    public static String yzyyUnit(int i, MemberApplyDO memberApplyDO, String unitTraSynthesis, String electronic, String strDate)throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(900, 1200, ImageIO.read(new File(unitTraSynthesis)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(0, 0, 0);
        g.setColor(color);
//        g.setFont(new Font("方正粗雅宋", Font.BOLD, 30));
        String year = strDate.substring(0, 4);//年份
        String month = strDate.substring(5, 6);//月份
        String month1 = strDate.substring(6, 7);//月份
        month=month.replace("0","");
        String monthFinally=month+month1;


        String[] intentions = {"常务副理事单位", "副理事单位", "常务理事单位", "理事单位"};
        String intent=intentions[memberApplyDO.getIntention()];
        g.setFont(new Font("黑体", Font.BOLD, 55));
        //申请意向
        if(intent.length()>6){
            g.drawString(intent, 250, 695);
        }else if (intent.length()>5){
            g.drawString(intent, 280, 695);
        }else if (intent.length()>4) {
            g.drawString(intent, 320, 695);
        }else {
            g.drawString(intent, 335, 695);
        }
        g.setFont(new Font("黑体", Font.PLAIN, 29));
        //证书落笔-年份
        g.drawString(year, 310, 898);
        //证书落笔-月份
        g.drawString(monthFinally, 415, 898);

        //证书落笔-尾部年份
        g.drawString("2028", 505, 898);
        //证书落笔-尾部月份
        g.drawString("7", 616, 898);

        String year1 = strDate.substring(2, 3);
        String year2 = strDate.substring(3, 4);

        String[] years = {"〇","一", "二", "三", "四","五", "六", "七", "八","九"};
        year1=years[Integer.parseInt(year1)];
        year2=years[Integer.parseInt(year2)];
        String[] months = {"〇","一", "二", "三", "四","五", "六", "七", "八","九"};
        String[] monthss = {"十"};

        month1=months[Integer.parseInt(month1)];
        g.setFont(new Font("黑体", Font.BOLD, 38));
        //证书落笔-生成年份
        g.drawString(year1, 375, 949);
        g.drawString(year2, 410, 949);
        //证书落笔-生成月份
        if (StringUtils.isNotBlank(month)){
            month=monthss[Integer.parseInt(month)-1];
            g.drawString(month, 490, 949);
            g.drawString(month1, 525, 949);
        }else {
            g.drawString(month1, 513, 949);
        }


        //完成模板修改
        g.dispose();

        String outPutPath;
        if(i == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + memberApplyDO.getContractName() +"单位"+ ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + memberApplyDO.getContractName() +"单位"+ ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));
        return outPutPath;
    }

//    public static void main(String[] args) throws IOException {
//        MemberApplyDO applyDO=new MemberApplyDO();
//        applyDO.setIntention(2);
//        applyDO.setContractName("聂成聂·聂成聂成");
////        String personalTraSynthesis="D:/upload/danweizhenshu.jpg";
//        String personalTraSynthesis="D:/upload/grenpinshu.jpg";
//        yzyyPersonal(1,applyDO,personalTraSynthesis,"", "2024-12-01 05:05:05");
////        yzyyUnit(1,applyDO,personalTraSynthesis,"", "2024-06-01 05:05:05");
//    }
    public static String yzyyPersonal(int i, MemberApplyDO memberApplyDO, String personalTraSynthesis, String electronic, String strDate) throws IOException{
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(personalTraSynthesis)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(0, 0, 0);
        g.setColor(color);
        g.setFont(new Font("思源宋体", Font.PLAIN, 30));

        String year = strDate.substring(0, 4);//年份
        String month = strDate.substring(5, 6);//月份
        String month1 = strDate.substring(6, 7);//月份
        String month2=month.replace("0","");
        String monthFinally=month2+month1;
        if (memberApplyDO.getContractName().length()>5){

            g.setFont(new Font("思源黑体", Font.PLAIN, 20));
            int a = 355-counthanzi(memberApplyDO.getContractName())*16;
            //聘书姓名
            g.drawString(memberApplyDO.getContractName(), a, 359);
        }else if (memberApplyDO.getContractName().length() == 5){
            g.setFont(new Font("思源黑体", Font.PLAIN, 26));
            int a = 340-counthanzi(memberApplyDO.getContractName())*18;
            //聘书姓名
            g.drawString(memberApplyDO.getContractName(), a, 359);
        }else {
            g.setFont(new Font("思源黑体", Font.PLAIN, 29));
            int a = 322-counthanzi(memberApplyDO.getContractName())*18;
            //聘书姓名
            g.drawString(memberApplyDO.getContractName(),a , 359);
        }
        String[] intentions = {"常务副理事单位", "副理事单位", "常务理事单位", "理事单位"};
        String intent=intentions[memberApplyDO.getIntention()];
        g.setFont(new Font("思源宋体", Font.BOLD, 41));
        //申请意向
        if(intent.length()>6){
            g.drawString(intent, 400, 440);
        }else if (intent.length()>5){
            g.drawString(intent, 420, 440);
        }else if (intent.length()>4) {
            g.drawString(intent, 440, 440);
        }else {
            g.drawString(intent, 465, 440);
        }
        g.setFont(new Font("思源宋体", Font.PLAIN, 27));
        //证书落笔-年份
        g.drawString(year, 380, 517);
        if (month.contains("0")){
            //证书落笔-月份
            g.drawString(monthFinally, 497, 517);
        }else {
            g.drawString(monthFinally, 500, 517);
        }


        //证书落笔-尾部年份
        g.drawString("2028", 594, 517);
        //证书落笔-尾部月份
        g.drawString("7", 712, 518);

        g.setFont(new Font("思源宋体", Font.PLAIN, 24));
        //证书落笔-生成年份
        g.drawString(year, 686, 648);
        //证书落笔-生成月份
        g.drawString(monthFinally, 782, 648);



        if(i == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronic);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 755, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            System.out.println("进入带印章方法+++++++++++++++++++++++++++++++++++++++++++印章地址为"+electronic);
        }

        //完成模板修改
        g.dispose();

        String outPutPath;
        if( i== 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + memberApplyDO.getContractName() +"个人" + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + memberApplyDO.getContractName() +"个人" + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));
        return outPutPath;
    }


    public static String overStoragEngineerImage(int type, String backgroundPath, String stuName, String workUnit, String idCard, String cerNumber, String numPeriods, String traYear, String traMath, String traDay, String cerYear, String cerMath, String cerDay, String electronicSeal, String practiceItem) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        System.out.println(backgroundPath);
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        if(stuName.length()>4){
            g.setFont(new Font("思源黑体", Font.PLAIN, 27));
            int a = 230-counthanzi(stuName)*18;
            g.drawString(stuName, a, 348);
        }else {
            g.setFont(new Font("思源黑体", Font.PLAIN, 29));
            int a = 255-counthanzi(stuName)*18;
            g.drawString(stuName, a, 348);
        }

//        if (counthanzi(stuName) == 2) {
//            //考生姓名
//            g.drawString(stuName, 694, 231);
//        } else if (counthanzi(stuName) == 3) {
//            //考生姓名
//            g.drawString(stuName, 684, 231);
//        } else {
//            //考生姓名
//            g.drawString(stuName, 674, 231);
//        }

        g.setFont(new Font("思源黑体", Font.PLAIN, 25));
        g.drawString(practiceItem, 148, 403);

        g.setFont(new Font("思源黑体", Font.PLAIN, 28));
        //证书文字-培训年份
        g.drawString(traYear, 410, 349);
        //证书文字-培训月份
        g.drawString(traMath, 524, 349);
        //证书文字-培训日期
        g.drawString(traDay, 605, 349);

        //考核期数
        g.drawString(numPeriods, 228, 459);

        //证书落笔-培训年份
        g.drawString(cerYear, 710, 349);
        //证书落笔-培训月份
        g.drawString(cerMath, 814, 349);
        //证书落笔-培训日期
        g.drawString(cerDay, 894, 349);
        g.setFont(new Font("思源黑体", Font.PLAIN, 22));

        //身份证
        g.drawString(idCard, 467, 504);
        //证书编号
        g.drawString(cerNumber, 467, 543);

        //证书最后-培训年份
        g.drawString(cerYear, 452, 680);
        //证书最后-培训月份
        g.drawString(cerMath, 530, 680);
        //证书最后-培训日期
        g.drawString(cerDay, 580, 680);
        //工作单位
        g.drawString(workUnit, 467, 583);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }



        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    public static String vocationalSkills(int type, String backgroundPath, String stuName, String cerNumber, String traYear, String traMath, String traDay, String cerYear, String electronicSeal, String practiceItem) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        System.out.println(backgroundPath);
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        if(stuName.length()>4){
            g.setFont(new Font("思源黑体", Font.PLAIN, 26));
            int a = 218-counthanzi(stuName)*18;
            g.drawString(stuName, a, 340);
        }else {
            g.setFont(new Font("思源黑体", Font.PLAIN, 27));
            int a = 232-counthanzi(stuName)*18;
            g.drawString(stuName, a, 340);
        }
        g.setFont(new Font("思源黑体", Font.PLAIN, 27));
        //证书文字-培训年份
        g.drawString(traYear, 295, 341);
        //证书文字-培训月份
        g.drawString(traMath, 395, 341);
//        //证书文字-培训日期
//        g.drawString(traDay, 605, 349);

        g.setFont(new Font("思源黑体", Font.PLAIN, 25));
        //查询网址
        g.drawString(practiceItem, 479, 523);
        //证书编号
        g.drawString(cerNumber, 479, 479);
        //获证年份
        g.drawString(cerYear, 479, 567);




        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

//


    public static String prizeImageYXAL(int type, String backgroundPath, String stuName, String cerNumber, String cerYear, String cerMath, String cerDay, String workUnit, String electronicSeal, String numPeriods, String traYear) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        System.out.println(backgroundPath);
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setColor(color);
        if(stuName.length()>4){
            g.setFont(new Font("思源黑体", Font.PLAIN, 25));
            int a = 530-counthanzi(stuName)*18;
            g.drawString(stuName, a, 368);
        }else {
            g.setFont(new Font("思源黑体", Font.PLAIN, 26));
            int a = 540-counthanzi(stuName)*18;
            g.drawString(stuName, a, 368);
        }
        g.setFont(new Font("思源黑体", Font.PLAIN, 27));
        //证书落笔-培训年份
        g.drawString(cerYear, 747, 680);
        //证书落笔-培训月份
        g.drawString(cerMath, 842, 680);
        //培训年度
        g.drawString(traYear, 796, 368);
        //工作单位
        g.drawString(workUnit, 152, 305);


        if(type == 0){
            //电子公章，以水印的形式插入
            //水印图象的路径 水印一般为gif或者png的，这样可设置透明度
            ImageIcon imgIcon = new ImageIcon(electronicSeal);
            //得到Image对象。
            Image img = imgIcon.getImage();
            float alpha = 1.0f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            // 表示水印图片的位置
            g.drawImage(img, 720, 540, 150, 150, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        }

        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }

    public static void main(String[] args) {
        String xingming = "李小璐·马尔咋呼"; //姓名
        String zhengshubianhao = "JZ20412008010093"; //证书编号

        String workUit="测试工作单位";
        String kaishinian = "2022"; //培训开始日期
        String kaishiyue = "11"; //培训开始日期
        String kaishiri = "11"; //培训开始日期
        String jieshunian = "2023"; //培训截止日期
        String jieshuyue = "09"; //培训截止日期
        String jieshuri = "23"; //培训截止日期

        String shijianxiangmu = "这是实践项目"; //实践项目
        String xianxiaxueshi = "5"; //线下学时
        String xianshangxueshi = "10"; //线上学时
        String qitaxueshi = "20"; //其它学时

        String huozhengriqinian = "2023"; //获证日期年
        String huozhengriqiyue = "09"; //获证日期月
        String huozhengriqiri = "23"; //获证日期日
//
        String personalTraSynthesis="D:/upload/youxiuzuzhis.jpg";
        try {
            prizeImageYXZZ(1,personalTraSynthesis,xingming, zhengshubianhao,
                    kaishinian,kaishiyue, jieshunian);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    public static String prizeImageYXZZ(int type, String backgroundPath, String stuName, String cerNumber, String cerYear, String cerMath, String traYear) throws IOException {
        // 设置背景图片大小，暂时按照分辨率是96像素/英寸时，A4纸的尺寸的图像的像素是794×1123；(windows默认)
        //将实际尺寸转换成英寸，再按照96像素/英寸比例计算得到大小
//        BufferedImage backgroundImage1 = ImageIO.read(new File(backgroundPath));//如果想获得原始图片，可直接用imageIo
        System.out.println(backgroundPath);
        BufferedImage backgroundImage = resizeImage(1123, 794, ImageIO.read(new File(backgroundPath)));

        //在背景图片中添加入需要写入的信息，
        Graphics2D g = backgroundImage.createGraphics();

        //统一对文字去除锯齿边框
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //设置为透明覆盖
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));

        Color color = new Color(51, 51, 51);
        g.setFont(new Font("思源黑体", Font.PLAIN, 26));

        g.setColor(color);
        if(stuName.length()>4){
            int a = 215-counthanzi(stuName)*18;
            g.drawString(stuName, a, 298);
        }else {
            int a = 225-counthanzi(stuName)*18;
            g.drawString(stuName, a, 298);
        }
        g.setFont(new Font("思源黑体", Font.PLAIN, 25));
        //培训年度
        g.drawString(traYear, 220, 355);
        g.setFont(new Font("思源黑体", Font.PLAIN, 23));
        //证书落笔-培训年份
        g.drawString(cerYear, 770, 669);
        //证书落笔-培训月份
        g.drawString(cerMath, 851, 668);





        //完成模板修改
        g.dispose();

        String outPutPath;
        if(type == 0){
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesis/" + stuName + cerNumber + ".png";
        }else{
            outPutPath = ValuesUtil.localUrl + "/upload/traSynthesisNoSale/" + stuName + cerNumber + ".png";
        }

        // 输出新的图片
        ImageIO.write(backgroundImage, "png", new File(outPutPath));

        return outPutPath;
    }
}


